package cmd

import (
	"context"
	_ "gf-vben-admin/internal/config/casbin"
	_ "gf-vben-admin/internal/config/driver"
	"gf-vben-admin/internal/config/log"
	_ "gf-vben-admin/internal/config/log"
	"gf-vben-admin/internal/config/permission"
	"gf-vben-admin/internal/controller/auth"
	"gf-vben-admin/internal/middle"
	sysRouter "gf-vben-admin/internal/router/system"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			log.InitLog(ctx)
			s := g.Server()
			s.Use(middle.MiddlewareHandlerResponse, ghttp.MiddlewareCORS)
			s.Group("/", func(group *ghttp.RouterGroup) {
				group.Bind(auth.Auth)
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(middle.Auth, middle.CasBin)
					sysRouter.InitSystemRouter(group)
				})
			})
			_ = s.Start()
			permission.InitPermission(ctx)
			//casbin.Init()
			g.Wait()
			return nil
		},
	}
)

//func register(group *ghttp.RouterGroup) {
//	group.Group("/sys", func(group *ghttp.RouterGroup) {
//		system.InitSysDictType(group) //字典
//	})
//}
